import { Modal } from "ant-design-vue";
import { decrypt } from "@/utils/decrypt";

/**
 * @date: 2022/11/9
 * @author jikaidi
 * @Description: 文件预览
 * @method previewFile
 * @param {String} url 文件url
 * @param {String} id 文件id
 * @return {undefined} 无返回值
 */
export function preview(url, id) {
  if (!url) {
    Modal.error({
      title: "错误",
      content: "文件地址不存在，无法预览",
    });
    return undefined;
  }
  let decryptUrl = decrypt(url);
  sessionStorage.setItem(`manualfilling-${id}`, decryptUrl);
  const previewUrl = `${window.location.protocol}//${
    window.location.host
  }/preview?name=${`manualfilling-${id}`}`;
  const data = {
    type: "ACTION_TAB_ADD",
    payload: {
      name: "Other",
      url: previewUrl,
      title: "文件详情",
      watermark: "1",
    },
  };
  // eslint-disable-next-line no-undef
  magicMessage(data);
}
